﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--    <link href="/static/css/dialog.css" rel="stylesheet"/>-->
    <!--    <script src="/static/js/dialog.js"></script>-->
    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/layui.js"></script>


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>
<style>
    .layui-table-body .layui-table-cell {
        height:90px;
        line-height: 90px;
    }
</style>
<div class="newtest">
    <div class="container new_serach">
        {volist name="powerList" id="vo"}
        <a class="btn btn-primary btn-sm" href="{$vo['url']}">{$vo.name}</a>
        {/volist}
    </div>


    <div class="container new_serach">
        <span> 平台名称：</span>
        <div class="layui-inline">
            <input class="form-control serach_key" name="platform" type="text">
        </div>
        <button class="layui-btn layui-btn-sm" data-type="reload">搜索</button>
    </div>


    <div class="new_main">

        <table class="layui-hide" id="demo" lay-filter="demo"></table>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <a class="layui-btn layui-btn-sm" href="{:Url('admin/System/config')}">添加平台</a>
            </div>
        </script>

        <script type="text/html" id="barDemo">
            <a class="btn-sm btn-primary" href="{:Url('admin/System/config')}?id={{d.id}}" >编辑</a>
            <a class="btn-sm btn-danger" lay-event="del">删除</a>
        </script>


        <script type="text/html" id="switchTpl">
            <!--启用禁用操作-->
            <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
        </script>

    </div>
</div>


</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>


<script>

    //启用禁用
    function updateProductStatus(ProductId,type,status) {
        $.ajax({
            type: "post",
            url: "{:URL('admin/System/slideStatus')}",
            data: {id:ProductId,type:type,status:status},
            dataType: "json",
            success: function(data){}
        });
    }

    var modal = new yii.modal();
    $(function() {

        //删除操作
        modal.on("newsave", function (data) {
            var id = data;
            var newthat = $(this);
            $.ajax({
                type: "post",
                url: "{:URL('admin/System/delConfig')}",
                data: {id: id},
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        window.parent.location.reload();
                        //window.location.href = "{:URL('index/index/index')}";
                    }else{
                        layer.alert(data.msg);
                        $(modal.getid()).find(".js_close").click();
                    }
                }
            });
        });






    });


    layui.use(['form','jquery','layer','laydate','table'], function() { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            ,range: true
        });

        //搜索操作
        $('.layui-btn').click(function () {
            var platform = $('input[name="platform"]').val();
            table.reload('demo', {
                url:"{:URL('admin/system/index')}"
                , request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , where: {
                    platform: platform,
                }
                , page: {
                    curr: 1
                }
            });
        });

        table.render({
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            elem: '#demo', // 表格id
            url:"{:URL('admin/system/index')}",
            where:{type:'list'},
            title: '单元列表',
            page: true, // 树形表格一般是没有分页的
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80, align:'center'}
                ,{field: 'name', title: '名称', align:'center'}
                ,{field: 'avatar', title: '平台缩略图',width:120, align:'center'}
                ,{field: 'status', title: '状态',width:120, align:'center',templet: '#switchTpl', unresize: true}
                ,{field: 'addtime', title: '添加时间',sort: true,width:180, align:'center'}
                ,{fixed: 'right',title: '操作', width:360, align:'center', toolbar: '#barDemo'}
            ]],
            done: function() {
                layer.closeAll('loading');
            }
        });

        //监听启用禁用操作
        form.on('switch(sexDemo)', function(obj){
            var id = this.value;
            var state = obj.elem.checked;
            if (state == true) {
                //上线
                updateProductStatus(id,'status','1');
            } else {
                //下线
                updateProductStatus(id,'status','2');
            }
        });

        //监听行工具事件
        table.on('tool(demo)', function(obj){
            switch(obj.event){
                case 'del':
                    var id = obj.data.id;
                    layer.confirm('该操作会删除该平台的所有文件，是否确定操作?', function(index){
                        delOperation(id,obj,index);
                    });
                    break;
            };
        });

        //删除
        function delOperation(id,obj,index,reload=0) {
            $.ajax({
                type: "post",
                url: "{:URL('admin/system/delConfig')}",
                data: {id:id},
                dataType: "json",
                success: function(data){
                    layer.alert(data.msg);
                    if(data.code==0){
                        if(reload==0){
                            obj.del();
                            layer.close(index);
                        }else{
                            //执行重载
                            table.reload('demo');
                            layer.close(index);
                        }
                    }
                }
            });
        }



    });

</script>



</html>
